﻿using AutoMapper;
using MediatR;
using RedDragon.Common.Domain.AuthorizeRBAC;
using RedDragon.Common.Infrastructure.Interface;
using RedDragon.RBAC.API.Application.Common.Client;
using T.Common.Domain.Common;
namespace RedDragon.RBAC.API.Application.Common.Storehouse
{
    public class ShowStorehouseHandler : IRequestHandler<ShowStorehouseCommand, Result>
    {
        /// <summary>
        /// mapper
        /// </summary>
        private readonly IMapper mapper;
        /// <summary>
        /// 入库仓储
        /// </summary>
        public readonly IBaseRepository<Storehouses> StorehousesRepository;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="mapper"></param>
        /// <param name="StorehousesRepository"></param>
        public ShowStorehouseHandler(IMapper mapper, IBaseRepository<Storehouses> StorehousesRepository)
        {
            this.mapper = mapper;
            this.StorehousesRepository = StorehousesRepository;
        }
        /// <summary>
        /// 入库列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(ShowStorehouseCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            var list = await (await StorehousesRepository.GetAll()).Where(x=>x.IsDel==0) .ToArrayAsync();
            result.Data = list;
            return result;
        }
    }
}
